package com.supreme.proxyserver.controller;

import com.alibaba.fastjson.JSONObject;
import com.supreme.commonboot.utils.AjaxResp;
import com.supreme.proxyserver.config.props.ApplicationProps;
import com.supreme.proxyserver.config.props.ConfigCenterProps;
import com.supreme.proxyserver.config.props.SpringDatasourceProps;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "props")
public class PropsController {

    @Resource
    private Environment environment;

    @Resource
    private ApplicationProps applicationProps;

    @Resource
    private SpringDatasourceProps springDatasourceProps;

    @Resource
    private ConfigCenterProps configCenterProps;

    /*@Autowired
    public PropsController(Environment environment, ApplicationProps applicationProps, SpringDatasourceProps springDatasourceProps) {
        this.environment = environment;
        this.applicationProps = applicationProps;
        this.springDatasourceProps = springDatasourceProps;
    }*/

    @GetMapping(value = "getEnvProps/{key}")
    public AjaxResp getEnvProps(@PathVariable(value = "key") String key) {
        String property = this.environment.getProperty(key);
        return new AjaxResp(property);
    }

    @GetMapping(value = "getSimpleProps")
    public AjaxResp getSimpleProps() {
        String springApplicationName = applicationProps.getSpringApplicationName();
        return new AjaxResp(springApplicationName);
    }

    @GetMapping(value = "getConfigProps")
    public AjaxResp getConfigProps() {
        String applicationName = springDatasourceProps.getName();
        return new AjaxResp(applicationName);
    }

    @GetMapping(value = "getConfigCenterProps")
    public AjaxResp getConfigCenterProps() {
        final String result = configCenterProps.toString();
        return new AjaxResp(result);
    }
}
